@extends('admin.index')
@section('title','后台分类添加')
 @section('con')
 <div class="row">
 	@if (count($errors) > 0)
	    <div class="alert alert-danger">
	        <ul>
	            @foreach ($errors->all() as $error)
	                <li>{{ $error }}</li>
	            @endforeach
	        </ul>
	    </div>
	@endif
    <div class="col-lg-6 col-lg-offset-3" >
        <form role="form" method="post" action="{{url('/admin/type/insert')}}" target="if_upload" enctype="multipart/form-data">
            <div class="form-group">
                <label>选择分类</label>
                <select class="form-control" name='tid'>
                 @foreach($videos as $k=>$v)
                    <option value='{{$v->id}}'>{{$v->type}}</option>
                 @endforeach  
                </select>
            </div>
                <input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value='hm'>
            <div class="form-group">
                <label>视频名</label>
                <input class="form-control" type="text" name="film" value="">
                <p class="help-block"></p>
            </div>
            <div class="form-group">
                <label>收费</label>
                <select class="form-control" name="vips" >
                    <option value="0">免费</option>
                    <option value="1">付费</option>
                </select>
                <p class="help-block"></p>
            </div>
            <div class="form-group">
                <label>简介</label>
                <input class="form-control" type="text" name="content" value="">
                <p class="help-block"></p>
            </div>
            <div class="form-group">
                <label>详细说明</label>
                <input class="form-control" type="text" name="describe" value="">
                <p class="help-block"></p>
            </div>
            <iframe name='if_upload' style='display: none;'></iframe>
            <div id="zhu" class="progress" style="display:none;">
                <div id="jdt" class="progress-bar progress-bar-striped active" style="">
                    <div style="text-align: center;line-height: 20px" id='s'>0.0</div>
                </div>
            </div>
            <div class="form-group">
                <label>视频海报</label>
                <input  type="file" name="url" value="">
            </div>
            <div class="form-group">
                <label>视频文件</label>
                <input  type="file" name="upload" value="">
            </div>
            {{ csrf_field() }}
            <button class="btn btn-default" type="submit">提交</button>
            <button class="btn btn-default" type="reset">重置</button>
        </form>
    </div>
 </div>  
 @endsection
 @section('js')
 <script type="text/javascript">
    $.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
    });

    var p=-1;
    $(document).ready(function(){
        $('form').submit(function(){
            if($('input[name=upload]').val() != '' && $('input[name=url]').val() != '' && $('input[name=describe]').val() != ''
                 && $('input[name=content]').val() != '' && $('input[name=film]').val() != ''){
                    p=0;
                    showProgress();
            }else{
                    $('#successMessage').text('请填写信息').show(1000);
                        //定时关闭消息
                        setTimeout(function(){
                            $('#successMessage').hide(1000);
                        },2000);
            } 
              
        });

    });

    function showProgress(){
        $.get('/admin/type/storage?s'+Math.random(),function(data){
            if(data>0){
            p=data;
            }else if(p>0 && data==1){
            p=1;
            // console.log(p);
            }
            $('#zhu').css('display','');
            $('#s').html((p*100).toFixed(2)+"%");
            $('#jdt').css('width',500*p+"px");

        });
            if(p<1){
            setTimeout('showProgress()',1000);
            }else{
                window.location.href='/admin/type/videoindex';
            }
            
    }
 </script>
 @endsection
